<?php
session_start();
	require('./include/phpsqlajax_dbinfo.php');
	
	function parseToXML($htmlStr){
		$xmlStr=str_replace("&",'&amp;',$htmlStr);
		return $xmlStr; 
	}
	
	 // Opens a connection to a MySQL server.
	$connection = mysql_connect ($server, $username, $password);
	if (!$connection) 
	{
	  die('Not connected : ' . mysql_error());
	}
	
	// Sets the active MySQL database.
	$db_selected = mysql_select_db($database, $connection);
	if (!$db_selected) 
	{
	  die ('Can\'t use db : ' . mysql_error());
	}
	
	 //Set result charset to UTF-8
	 mysql_query('SET NAMES "utf8"');
	
	 // Select user profile information
	 $query = 'SELECT `email`,`organization` FROM `users` WHERE `idUsers`=(SELECT `idUsers` FROM `users` WHERE `username`="'.$_SESSION['username'].'")';
	 
	 $result = mysql_query($query);
	 if (!$result) 
	 {
	  die('Invalid query: ' . mysql_error());
	 }
	
	// Creates an array of strings to hold the lines of the XML file.
	header('Content-type: text/xml');
	$xml = array('<?xml version="1.0" encoding="UTF-8"?>');
	
	$xml[] = '<profile>';
	
	// Iterates through the rows, printing a node for each row.
	while ($row = @mysql_fetch_assoc($result)) 
	{
	  $xml[] = '<user>';
	  $xml[] = '<email>'.$row['email'].'</email>';
	  $xml[] = '<organization>'.$row['organization'].'</organization>';
	  $xml[] = '</user>';
	} 
	
	// End XML file
	$xml[] = '</profile>';
	$xmlOutput = join($xml);
	
	//Output XML file
	echo $xmlOutput;
?>